/***************************************************************************
 *   Copyright (C) 2011 by The rPem3d developers                           *
 *   elseifkk@users.sf.net                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef OKRUNCLS_H
#define OKRUNCLS_H

#include "okrunDlg.h"

#include <qprocess.h>
#include <qmutex.h>

#define CONFIG ".okrunrc"
#define SCRPATH_DEF "/usr/local/pem/bin"
#define SENDC_DEF "sendc"
#define PING_DEF "/sbin/ping -t 3 -c 3"

class okRunCls: public okRunDlg {
    Q_OBJECT

public:
    okRunCls(QWidget *parent = 0, const char *name = 0);

private:
    void sendCommands();
    void printLbls();
    void procLine(QString,int,bool full=true);
    int check_scr(QString s);
    void printmsg(QString s, QString c="navy blue");
    void setEnabledSendButs(bool,bool);
    void changeFontSizeMess(int d);
    void changeFontSizeCom(int d);
    void loadConfig(QString f);
    void saveConfig(QString f);
    void addHistRemoteHost();
    bool isValidPort();

private:
    int numcom;
    bool sendReady;
    int maxcomlen;

    QProcess *sp;
    QProcess *sp1;
    QProcess *pp; // ping proc

    int repeatCount;
    int repeatInterval;
    QString oneCommand;
    int currentRow;
    QMemArray<int> runList;
    QPixmap *okpic;
    QPixmap *ngpic;
    QPixmap *fkpic;
    QPixmap *erpic;
    bool killed;
    bool killed1;
//     bool editVeto;
    QMutex editMT;
    int currentStepNum;
    QString rep;
    int currentRowHeight;

    QTimer *loopt;
    QString SCRPATH;
    QString HOME;
    QString PING,SENDC;

private slots:
    void sendAllSlot();
    void cleMessSlot();
    void finSlot();
    void addSlot();
    void readSlot();
    void openFileSlot();
    void updateButsSlot();
    void sendDonep();
    void slotReadStdoutp();
    void slotReadStderrp();
    void sendDone();
    void slotReadStdouts();
    void slotReadStderrs();
    void sendDone1();
    void slotReadStdout1();
    void slotReadStderr1();
    void enableRepeatSlot();
    void sendOneSlot();
    void insertFileSlot();
    void appendFileSlot();
    void killSendSlot();
    void killSend1Slot();
    void sendSelectedSlot();
    void selectClearSlot();
    void selectAllSlot();
    void uncommentSlot();
    void commentSlot();
    void removeSlot();
    void pingSlot();
    void saveSlot();
    void editComListSlot(int r, int c);
    void cleStaSlot();
    void sendACommand();
    void shrMessSlot();
    void magMessSlot();
    void shrComSlot();
    void magComSlot();
    void sendHereSlot();

protected:
    void keyPressEvent ( QKeyEvent *e );
    void closeEvent(QCloseEvent *e);
};

#endif
